package examples.java.concurrency;

/**
 * @author Bill
 * @version 2013-05-30
 */
public class NotifyWaitTest {

    public static void main(String[] args) {

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("worker staring....");

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }

                System.out.println("worker done....");

                synchronized (NotifyWaitTest.class) {
                    NotifyWaitTest.class.notify();
                }
            }
        }).start();

        synchronized (NotifyWaitTest.class) {
            try {
                NotifyWaitTest.class.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
        System.out.println("finally, I am done.");

    }

}
